package com.kk.config;

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * the class of spring_security_demo
 *
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2023-06-14
 */

@Configuration
public class ErrorPageConfig {

    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
        WebServerFactoryCustomizer<ConfigurableWebServerFactory> webCustomizer = factory -> {
            ErrorPage[] errorPages = new ErrorPage[]{
                    new ErrorPage(HttpStatus.FORBIDDEN, "/403"),
                    new ErrorPage(HttpStatus.NOT_FOUND, "/404"),
                    new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500"),
            };
            factory.addErrorPages(errorPages);
        };
        return webCustomizer;
    }
}
